<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">储位号</label>
        <el-input v-model="query.storageCode" clearable placeholder="储位号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">车间</label>
        <el-input v-model="query.storageType" clearable placeholder="车间" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">容器号</label>
        <el-input v-model="query.containerCode" clearable placeholder="容器号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">储位二维码</label>
        <el-input v-model="query.qrCode" clearable placeholder="储位二维码" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">1禁用0启用</label>
        <el-input v-model="query.enable" clearable placeholder="1禁用0启用" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="120px">
          <el-form-item label="储位号" prop="storageCode">
            <el-input v-model="form.storageCode" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="车间" prop="storageType">
            <el-input v-model="form.storageType" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="容器号" prop="containerCode">
            <el-input v-model="form.containerCode" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="储位二维码" prop="qrCode">
            <el-input v-model="form.qrCode" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="1禁用0启用" prop="enable">
            未设置字典，请手动设置 Select
          </el-form-item>
          <el-form-item label="储位长" prop="storageLength">
            <el-input v-model="form.storageLength" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="储位宽" prop="storageWidth">
            <el-input v-model="form.storageWidth" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="储位高" prop="storageHeight">
            <el-input v-model="form.storageHeight" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="储位入库锁定容器" prop="inboundLockContainer">
            <el-input v-model="form.inboundLockContainer" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="储位出库锁定容器" prop="outboundLockContainer">
            <el-input v-model="form.outboundLockContainer" style="width: 250px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="storageCode" label="储位号" />
        <el-table-column prop="storageType" label="车间" />
        <el-table-column prop="containerCode" label="容器号" />
        <el-table-column prop="qrCode" label="储位二维码" />
        <el-table-column prop="enable" label="1禁用0启用" />
        <el-table-column prop="storageLength" label="储位长" />
        <el-table-column prop="storageWidth" label="储位宽" />
        <el-table-column prop="storageHeight" label="储位高" />
        <el-table-column prop="inboundLockContainer" label="储位入库锁定容器" />
        <el-table-column prop="outboundLockContainer" label="储位出库锁定容器" />
        <el-table-column v-if="checkPer(['admin','storage:edit','storage:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudStorage from '@/api/work/storage'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, storageCode: null, storageType: null, containerCode: null, qrCode: null, enable: null, storageLength: null, storageWidth: null, storageHeight: null, inboundLockContainer: null, outboundLockContainer: null }
export default {
  name: 'Storage',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: 'storage', url: 'api/storage', idField: 'id', sort: 'id,desc', crudMethod: { ...crudStorage }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'storage:add'],
        edit: ['admin', 'storage:edit'],
        del: ['admin', 'storage:del']
      },
      rules: {
        storageCode: [
          { required: true, message: '储位号不能为空', trigger: 'blur' }
        ],
        storageType: [
          { required: true, message: '车间不能为空', trigger: 'blur' }
        ],
        containerCode: [
          { required: true, message: '容器号不能为空', trigger: 'blur' }
        ],
        qrCode: [
          { required: true, message: '储位二维码不能为空', trigger: 'blur' }
        ],
        enable: [
          { required: true, message: '1禁用0启用不能为空', trigger: 'blur' }
        ],
        storageLength: [
          { required: true, message: '储位长不能为空', trigger: 'blur' }
        ],
        storageWidth: [
          { required: true, message: '储位宽不能为空', trigger: 'blur' }
        ],
        storageHeight: [
          { required: true, message: '储位高不能为空', trigger: 'blur' }
        ],
        inboundLockContainer: [
          { required: true, message: '储位入库锁定容器不能为空', trigger: 'blur' }
        ],
        outboundLockContainer: [
          { required: true, message: '储位出库锁定容器不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'storageCode', display_name: '储位号' },
        { key: 'storageType', display_name: '车间' },
        { key: 'containerCode', display_name: '容器号' },
        { key: 'qrCode', display_name: '储位二维码' },
        { key: 'enable', display_name: '1禁用0启用' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
